/**
  *****************************************************************************
  * @file 
  * @brief 
  * @author luffy
  * @version V1.0.0
  * @date 2022/12/02
  *****************************************************************************
  */
#ifndef SC16IS7xx_H
#define SC16IS7xx_H

#include "dev_include.h"

/* Public defines ---------------------------------------------------------------------------*/
/*********************************************************************************************************
  General Register
*********************************************************************************************************/
#define    SC16IS7XX_RHR         0x00                                   /*  Read only Receive,Holding Register                     */
#define    SC16IS7XX_THR         0x00                                   /*  Write only,Transmit Holding Register                   */
#define    SC16IS7XX_IER         0x01                                   /*  Read or Write,Interrupt Enable Register                */
#define    SC16IS7XX_FCR         0x02                                   /*  Write only,FIFO Control Register                       */
#define    SC16IS7XX_IIR         0x02                                   /*  Read only,Interrupt Identification Register            */
#define    SC16IS7XX_LCR         0x03                                   /*  Read or Write,Line Control Register                    */
#define    SC16IS7XX_MCR         0x04                                   /*  Read or Write,Modem Control Register                   */
#define    SC16IS7XX_LSR         0x05                                   /*  Read only,Line Status Register                         */
#define    SC16IS7XX_MSR         0x06                                   /*  Read only,Modem Status Register                        */
#define    SC16IS7XX_SPR         0x07                                   /*  Read or Write,Scratchpad Register                      */
#define    SC16IS7XX_TCR         0x06                                   /*  Read or Write,Transmission Control Register            */
#define    SC16IS7XX_TLR         0x07                                   /*  Read or Write,Trigger Lever Register                   */
#define    SC16IS7XX_TXLVL       0x08                                   /*  Read only,Transmitter FIFO Level Register              */
#define    SC16IS7XX_RXLVL       0x09                                   /*  Read only,Receiver FIFO Level Register                 */
#define    SC16IS7XX_IODIR       0x0A                                   /*  Read or Write,Programmable I/O pins Direction register */
#define    SC16IS7XX_IOSTATE     0x0B                                   /*  Read or Write,Programmable I/O pins State register     */
#define    SC16IS7XX_IOINTENA    0x0C                                   /*  Read or Write,I/O Interrupt Enable register            */
#define    SC16IS7XX_IOCONTROL   0x0E                                   /*  Read or Write,I/O Control Register                     */
#define    SC16IS7XX_EFCR        0x0F                                   /*  read or write,Extra Features Control Register          */
/*********************************************************************************************************
  Special Register
*********************************************************************************************************/
#define    SC16IS7XX_DLL         0x00                                   /*  Read or Write,Divisor       */
                                                                        /*  Latch LSB                   */
#define    SC16IS7XX_DLH         0x01                                   /*  Read or Write,Divisor       */
                                                                        /*  Latch MSB                   */
/*********************************************************************************************************
  Enhanced Register
*********************************************************************************************************/
#define    SC16IS7XX_EFR         0x02                                   /*  Read or Write,Enhanced Features Register  */
#define    SC16IS7XX_XON1        0x04                                   /*  Read or Write,Xon1 word                   */
#define    SC16IS7XX_XON2        0x05                                   /*  Read or Write,Xon2 word                   */
#define    SC16IS7XX_XOFF1       0x06                                   /*  Read or Write,Xoff1 word                  */
#define    SC16IS7XX_XOFF2       0x07                                   /*  Read or Write,Xoff2 word                  */

/*********************************************************************************************************
  The Channel
*********************************************************************************************************/
#define    SC16IS7XX_CHA         0x00                                   /*  Channel A                   */
#define    SC16IS7XX_CHB         0x01                                   /*  Channel B                   */

#define    SC16IS7XX_FXTAL     1843200                                  /*  晶振频率                    */
#define    SPI_I2C             0                                        /*  操作接口，1为SPI，0为I2C    */
#define    SC16IS7XX_ADDR      0x9A                                     /*  I2C从机地址                 */

/* private config -----------------------------------------------------------*/

/* Public Struct ------------------------------------------------------------*/
typedef struct
{
    drv_i2c_t  i2c;
    //drv_gpio_t irq;
	drv_gpioexit_t irq;
} sc16is752_private_t;

typedef struct dev_sc16is752 dev_sc16is752_t;

struct dev_sc16is752
{
    /* ***************Public Parameter  *************** */
    const char *PIN_SCL;    //I2C时钟线-引脚
    const char *PIN_SDA;    //I2C数据线-引脚
    const char *PIN_IRQ;    //中断-引脚

    uint32_t                BaudRate;
	void    (*Int_Callback)(void);  
	
	
    /* ***************Public Method     *************** */
    void    ( *Write )  ( dev_sc16is752_t *, uint8_t, uint8_t* , uint8_t);
    void    ( *Read  )  ( dev_sc16is752_t *, uint8_t, uint8_t* , uint8_t);

    /* ***************Private Attributes*************** */
    sc16is752_private_t private;
};


/* Public enum --------------------------------------------------------------*/
//Different interrupt sources
typedef enum {
	RLS_ERROR = 0x06,
	TIME_OUT  = 0x0C,
	RHR       = 0x04,
	THR       = 0x02,
	MODEM     = 0x00,
	IOSTATE   = 0x30,
	XOFF      = 0x10,
	CTS_RTS   = 0x20
}Interrupt_Source;

/* Public Variable ----------------------------------------------------------*/
//Pointer

//Array

//Const


/* Pubilc function prototypes -----------------------------------------------*/
int Dev_Sc16is752_Init(dev_sc16is752_t *this);


                    
#endif /* SC16IS7xx_H */
